<%--
  Created by IntelliJ IDEA.
  User: etund
  Date: 2014/9/20
  Time: 19:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<center>
    <form action=""  enctype="application/x-www-form-urlencoded">
        <h3>请填写用户注册信息</h3>
        <table  border="1">
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="username" value="" id="username">
                    <div id="divcheck"></div>
                    <input type="button" name="checkusername" value="查看用户名" id="checkusername"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="psw" value=""></td>
            </tr>
            <tr>
                <td>确认密码:</td>
                <td><input type="password" name="confpsw" value=""></td>
            </tr>
            <tr>
                <td>出生日期:</td>
                <td><input type="text" name="birthday" value=""></td>
            </tr>
        </table>
    </form>
</center>
<script type="text/javascript">

            window.onload=function(){
                document.getElementById("checkusername").onclick=function(){
                        var xhr = createXmlHttpRequest();
                    xhr.onreadystatechange= function () {
                        if(xhr.readyState==4){
                            if(xhr.status==200||xhr.status==304){
                                var date = xhr.responseText;
                                document.getElementById("divcheck").innerHTML=date;
                            }
                        }
                    }
                    xhr.open("POST","/servlet/Servlet_2?time="+new Date().getTime());
                    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                    var username = document.getElementById("username");
                    xhr.send("username="+username);
                }
            }
            // a 创建XmlHttpRequest对象，固定写法
            function createXmlHttpRequest(){
                var xmlHttp;
                try{    //Firefox, Opera 8.0+, Safari
                    xmlHttp=new XMLHttpRequest();
                }catch (e){
                    try{    //Internet Explorer
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                    }catch (e){
                        try{
                            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                        }catch (e){}
                    }
                }
                return xmlHttp;
            }
</script>

</body>
</html>
